import {parseTime} from '@/utils'

export default {
  data() {
    return {
      downloadLoading: false
    }
  },
  methods: {
     /**
     * 导出
     * @param header 列头标题
     * @param filterField 导出字段
     * @param dataList 数据源
     * @param filename 文件名
     */
    export2Excel (header, filterField, dataList, filename) {
      import('@/vendor/Export2Excel').then(excel => {
        const data = this.formatJson(filterField, dataList)
        excel.export_json_to_excel({
          header: header,
          data,
          filename: filename
        })
        this.$message({message: '导出成功', type: "success"})
      })
    },
    formatJson (filterField, jsonData) {
      return jsonData.map(function (dataObj) {
        return filterField.map(function (field) {
          let fieldObj = dataObj[field]
          if (!fieldObj&&fieldObj!=0) {
            fieldObj = '--'
          }
          return fieldObj
        })
      })
    }
  }
}
